package com.example.myapplication;

import android.annotation.SuppressLint;
import android.database.Cursor;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Note implements Serializable {
  int noteId=-1;
  String authorName;
  String authorAccount;
  String noteTitle;
  Date createTime;
  Date updateTime;
  String noteContent="";//以后应该会替换

  boolean isFavour = false;
  String classify;//分组，以后在实现了





  public Note(String authorName, String authorAccount, String noteTitle) {
    this.authorName = authorName;
    this.authorAccount = authorAccount;
    this.noteTitle = noteTitle;
    createTime = new Date();
    updateTime = new Date();

  }

  public Note(int noteId, String authorName, String authorAccount, String noteTitle,
      Date createTime,
      Date updateTime, String noteContent) {
    this.noteId = noteId;
    this.authorName = authorName;
    this.authorAccount = authorAccount;
    this.noteTitle = noteTitle;
    this.createTime = createTime;
    this.updateTime = updateTime;
    this.noteContent = noteContent;

  }

  private Note() {

  }


  @SuppressLint("Range") public static Note fromCursor(Cursor cursor) {
    Note note = new Note();
    note.setNoteId(cursor.getInt(cursor.getColumnIndex("noteID")));
    note.setAuthorName(cursor.getString(cursor.getColumnIndex("authorName")));
    note.setAuthorAccount(cursor.getString(cursor.getColumnIndex("authorAccount")));
    note.setNoteTitle(cursor.getString(cursor.getColumnIndex("title")));
    String createTime = cursor.getString(cursor.getColumnIndex("createtime"));
    String updateTime = cursor.getString(cursor.getColumnIndex("updatetime"));

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    try {
      note.setCreateTime(dateFormat.parse(createTime));
      note.setUpdateTime(dateFormat.parse(updateTime));
    } catch (Exception e) {
      System.out.println("日期转换出现了问题");

      throw new RuntimeException(e);
    }
    note.setNoteContent(cursor.getString(cursor.getColumnIndex("content")));
    int flag = cursor.getInt(cursor.getColumnIndex("favour"));
    if (flag == 1) {
      note.setFavour(true);
    } else {
      note.setFavour(false);
    }

    return note;
  }



  public boolean isFavour() {
    return isFavour;
  }

  public void setFavour(boolean favour) {
    isFavour = favour;
  }

  public int getNoteId() {
    return noteId;
  }

  public void setNoteId(int noteId) {
    this.noteId = noteId;
  }

  public String getAuthorName() {
    return authorName;
  }

  public void setAuthorName(String authorName) {
    this.authorName = authorName;
  }

  public String getAuthorAccount() {
    return authorAccount;
  }

  public void setAuthorAccount(String authorAccount) {
    this.authorAccount = authorAccount;
  }

  public String getNoteTitle() {
    return noteTitle;
  }

  public void setNoteTitle(String noteTitle) {
    this.noteTitle = noteTitle;
  }

  public Date getCreateTime() {
    return createTime;
  }

  public void setCreateTime(Date createTime) {
    this.createTime = createTime;
  }

  public Date getUpdateTime() {
    return updateTime;
  }

  public void setUpdateTime(Date updateTime) {

    this.updateTime = updateTime;
  }

  public String getNoteContent() {
    return noteContent;
  }

  public void setNoteContent(String noteContent) {
    this.noteContent = noteContent;
  }
}
